import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'

// 开发环境配置
const isDevelopment = process.env.NODE_ENV === 'development'

// 生产环境配置（已注释）
// const isDevelopment = false
const BACKEND_URL = isDevelopment ? 'http://localhost:8000' : 'http://172.18.20.114:5155'
const FRONTEND_PORT = isDevelopment ? 3000 : 8084

export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    },
  },
  server: {
    host: '0.0.0.0',
    port: FRONTEND_PORT,
    proxy: {
      '/api': {
        target: BACKEND_URL,
        changeOrigin: true,
        secure: false
      }
    }
  },
  build: {
    outDir: 'dist',
    assetsDir: 'assets'
  }
})
